<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  </head>
  <body>
  	<input type="hidden" id="usertype" name="usertype" value="${usertype}"/>
	  <div class="row-fluid">
      <div class="span12">
		    <table id="tabGrid" ></table>
		    <div id="pager"></div>
	    </div>
    </div>  
		<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery/jqGridUtil.js"></script>
    <script type="text/javascript">
	    jQuery(function(){
				jQuery("#loading").hide();
	    	var config = {
	           	url:'<%=request.getContextPath() %>/answer/user/answerList.html?doType=query',
	           	colModel:[
	           		{label:'send_survey_user_assuser',name:"send_survey_user_assuser",index:'send_survey_user_assuser', key:true ,hidden:true},
	           		{label:'问卷名称',name:"survey_name",index:'survey_name'},
	           		{label:'RELATION',name:"relation",index:'relation',align:'center',hidden:true},
	           		{label:'答卷人',name:"user_nm",index:'user_nm',width:'50px'},
	           		{label:'类别',name:"relation_name",index:'relation_name',align:'center',width:'40px'},
	           		{label:'评估对象',name:"assess_user_nm",index:'assess_user_nm',width:'50px'},
	           		{label:'单位名称',name:"company_name",index:'company_name'},
	           		{label:'问卷发放时间',name:"send_start_dt",index:'send_start_dt',width:'100px'},
	           		{label:'答卷状态',name:"submit_name",index:'submit_name',align:'center',width:'50px'},
	           		{label:'send_end_dt',name:"send_end_dt",index:'send_end_dt',hidden:true},
	           		{label:'survey_flg',name:"survey_flg",index:'survey_flg',hidden:true},
	           		{label:'操作',name:"submit_flg",index:'submit_flg',formatter:showControl,align:'left',width:'100px'}
	           	],
	           	table:"#tabGrid",
	           	pager: "#pager",
	           	multiselect:false,
	            caption:"问卷信息列表"
	      };
	    	jQuery.loadGrid(config);
	    	jQuery("#tabGrid").setGridWidth(jQuery(".row-fluid").width());
	    });
			
	    // 显示链接
	    function showControl(cellValue,option,rowObject){
		    var usertype = jQuery("#usertype").val();
				var submit_flg =  rowObject.submit_flg;
				var survey_flg =  rowObject.survey_flg;
				var send_end_dt = rowObject.send_end_dt;
				if(survey_flg === '2'){
					return "&nbsp;";
				}
				// 已过期则不能再答卷
				if(send_end_dt != null && send_end_dt != "" && send_end_dt !="undefined"){
					var now = new Date().getTime();
					var end_dt = new Date(send_end_dt).getTime();

					if(now > end_dt){
						return "&nbsp;";
					}
					
					// 已提交不能再答卷
				}else if(submit_flg ==='2' || 'manager' == usertype){
					return "&nbsp;"
				}else{
					var url = "<%=request.getContextPath()%>/answer/user/showSurveyAnswer.html?send_survey_user_assuser=";
	    				url += rowObject['send_survey_user_assuser'];
	    				url +="&relation=";
	    				url += rowObject['relation'];
	    	  var urlTo = encodeURI(url);
	    	  return  "&nbsp;&nbsp;<input type='button' class='btn btn-mini btn-danger' value='答卷' title='答卷' onclick='refMain(\""+urlTo+"\")'>";
					//return  "<span class='badge badge-important' onclick='refMainContent(\""+urlTo+"\")'>答卷</span>"
				}
	    }

	    function refMain(url){

					var single = "";
					if(url.indexOf('?') == '-1'){
						single = "?";
					}else{
						single = "&";
					}
					var dt = new Date().valueOf();
					url += single+"date="+dt;
					jQuery("#mainContent").fadeOut(600, function() {
								jQuery("#loading").show();
				        $(this).load(url, function() {
				        	  jQuery("#loading").hide();
				            $(this).fadeIn(600);
				        });
			        });
				        
					//refMainContent(url);
	    }

	    /**
		    * 检索
		    * @param tabId
		    * @param jsonMap
		    */
	    function searchResult() {
	    	var map = {};
	    	map["survey_name"] = jQuery('#survey_name').val();
	    	search('tabGrid',map);
	    }

    </script>
  </body>
</html>
